package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.annotation.LogToDb;
import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Map<String, Object> listSupplier(Integer pageNumber, Integer pageSize, String supplierName) {
        List<Supplier> supplierList = supplierDao.selectSupplierPageByName((pageNumber - 1) * pageSize, pageSize, supplierName);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total", supplierList.size());
        map.put("rows", supplierList);
        return map;
    }

    @Override
    public boolean save(Supplier supplier) {
        if (supplier.getSupplierId() != null) {
            supplierDao.updateSupplierById(supplier);
        } else {
            supplierDao.insertSupplier(supplier);
        }
        return true;
    }

    @Override
    public boolean deleteBatch(String... supplierIds) {
        for (String supplierId : supplierIds) {
            supplierDao.deleteById(supplierId);
        }
        return true;
    }
}
